//
//  CategoryDetailViewController.m
//  Mall
//
//  Created by 孙飞燕 on 16/10/10.
//  Copyright © 2016年 孙飞燕. All rights reserved.
//

#import "CategoryDetailViewController.h"
#import "WaterfallCollectionViewCell.h"
#import "PuBuLiuLayout.h"
#import "GoodsDetailViewController.h"
@interface CategoryDetailViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,PuBuLiuLayoutDelegate>
@property (nonatomic,strong)UICollectionView *collectionView;
//@property (nonatomic,strong)
@end

@implementation CategoryDetailViewController
- (UICollectionView *)collectionView{
    if (!_collectionView) {
       PuBuLiuLayout *flowLayout = [[PuBuLiuLayout alloc]init];
        //设置列数
        flowLayout.columnNumber = 2;
        flowLayout.delegate = self;
        flowLayout.padding = 5;
        flowLayout.edgeInsets = UIEdgeInsetsMake(5, 5, 20, 5);
        _collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        //注册单元格
        [_collectionView registerClass:[WaterfallCollectionViewCell class] forCellWithReuseIdentifier:@"item"];

    }
    return _collectionView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.collectionView];
    self.collectionView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    // Do any additional setup after loading the view.
}
#pragma mark --- UITableView的代理方法
//分区数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
//每个分区下有多少个cell
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//    return self.allDataArray.count;
    return 30;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    WaterfallCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"item" forIndexPath:indexPath];
    cell.waterfallImage.image = [UIImage imageNamed:@"k3"];
    cell.waterfallLabel.text = @"瑞思迈";
    return cell;
}
//点击cell进入商品信息详情界面
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    GoodsDetailViewController *detailVC  = [[GoodsDetailViewController alloc]init];
    //进入下个界面时隐藏底下tabBar
    detailVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:detailVC animated:YES];
    //返回界面时显示tabbar
    self.hidesBottomBarWhenPushed = NO;
}
#pragma mark---布局文件的代理方法
- (CGFloat)puBuLiuLayoutHeightForItemAtIndex:(NSIndexPath *)index {
    return arc4random_uniform(80) + 120;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
